package com.android.cl.coludtf.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.cl.coludtf.R;
import com.android.cl.coludtf.appcliation.MyAppcliation;
import com.android.cl.coludtf.model.NinePalaces;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WorkTopAdapter extends BaseAdapter {
    LayoutInflater inflater;
    private List<NinePalaces> dataList;

    public WorkTopAdapter(List<NinePalaces> dataList) {

        super();// 继承自父类，用super可以调用父类的方法，实现父类方法中的功能，在添加你自己想实现的方法
        this.dataList = dataList;
        inflater = LayoutInflater.from(MyAppcliation.context);
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public NinePalaces getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;// = new ViewHolder(convertView);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.gridview_item, null, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.img.setImageResource(getItem(position).getImg());
        viewHolder.img.setTag(getItem(position).getUrl());
        viewHolder.text.setText(getItem(position).getText());
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.img)
        ImageView img;
        @BindView(R.id.text)
        TextView text;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
